package beans.factorys.support;

import beans.factorys.BeanFactory;
import beans.factorys.config.RunTimeBeanReference;
import beans.factorys.config.TypedStringValue;
import utils.StringUtils;

/**
 * Created by ZhaiGuaili on 2018/7/27.
 */
public class BeanDefinitionVlaueResolver {
    private BeanFactory factory;

    public BeanDefinitionVlaueResolver(BeanFactory factory){
        this.factory = factory;
    }

    public Object resolveValueIfNecessary(Object obj)throws Exception{
        if(obj instanceof RunTimeBeanReference){
            RunTimeBeanReference reference = (RunTimeBeanReference)obj;
            String refName = reference.getBeanName();
            Object tragetObj = factory.getBean(refName);
            return tragetObj;
        }else if(obj instanceof TypedStringValue){

            TypedStringValue typedStringValue = (TypedStringValue)obj;
            return typedStringValue.getValue();
        }else{
           throw new RuntimeException("the value " + obj +" has not implemented");
        }
    }


}
